package com.hyopt.modules.app.controller;

import com.github.lqccan.wechat.work.bot.Bot;
import com.github.lqccan.wechat.work.bot.msg.ArticleMsg;
import com.github.lqccan.wechat.work.bot.msg.ImageMsg;
import com.github.lqccan.wechat.work.bot.msg.MarkdownMsg;
import com.github.lqccan.wechat.work.bot.msg.TextMsg;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ChatBotSend
 * @Description TODO
 * @Author lijie
 * @Date 2023/2/8 12:51 星期三
 * @Version 1.0
 */

public class ChatBotSend {

        private Bot bot;

        /**
         * 构造机器人对象
         */
        @Before
        public void buildBot() {
            bot = new Bot("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=4afe16e2-985f-42bb-a5fb-5e1bf6844a75");
        }

        /**
         * 文字测试
         */
        @Test
        public void textTest() {
            buildBot();
            TextMsg textMsg = new TextMsg();
            textMsg.setContent("你好我是一只机器人");
            bot.send(textMsg);
        }

        /**
         * markdown测试
         */
        @Test
        public void markdownTest() {
            buildBot();
            MarkdownMsg markdownMsg = new MarkdownMsg();
            markdownMsg.setContent("实时新增用户反馈<font color=\"warning\">132例</font>，请相关同事注意。\n" +
                    "         >类型:<font color=\"comment\">用户反馈</font>\n" +
                    "         >普通用户反馈:<font color=\"comment\">117例</font>\n" +
                    "         >VIP用户反馈:<font color=\"comment\">15例</font>");
            bot.send(markdownMsg);
        }

        /**
         * 图片测试
         */
        @Test
        public void imageTest() {
            buildBot();
            ImageMsg imageMsg = new ImageMsg();
            //本地文件
            imageMsg.setFile(new File("E:\\网站模板\\壁纸\\123456789default.png"));
            //网络文件
//            imageMsg.setFile("https://i.loli.net/2020/02/04/znKwNdcSujE2i4l.png");
            bot.send(imageMsg);
        }

        /**
         * 图文测试
         */
        @Test
        public void articleTest() {
            buildBot();
            ArticleMsg articleMsg = new ArticleMsg();
            articleMsg.setTitle("周六上线聚餐选择");
            articleMsg.setDescription("点击图片链接投票");
            articleMsg.setUrl("https://tp.wjx.top/vm/O0YZNuQ.aspx#");
            articleMsg.setPicurl("https://zouqingwen.com/JC.jpg");
            bot.send(articleMsg);
        }

        /**
         * 多个图文测试
         */
        @Test
        public void articleListTest() {
            buildBot();
            List<ArticleMsg> list = new ArrayList<ArticleMsg>();
            for (int i = 1; i <= 3; i++) {
                ArticleMsg articleMsg = new ArticleMsg();
                articleMsg.setTitle("图文"+i);
                articleMsg.setDescription("这是一条图文消息");
                articleMsg.setUrl("https://www.3kkg.com");
                articleMsg.setPicurl("https://i.loli.net/2020/02/04/znKwNdcSujE2i4l.png");
                list.add(articleMsg);
            }
            bot.send(list);
        }



}
